/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/Assert.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Clock.h>

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>

/* Board Header files */
#include "Board.h"

/* EasyLink API Header files */
#include "easylink/EasyLink.h"

/********************************************************************************/
#include "config.h"
#include "soft_timer.h"
/********************************************************************************/
#define RFEASYLINKUSER_TASK_STACK_SIZE    2048
#define RFEASYLINKUSER_TASK_PRIORITY      2

/***** Variable declarations *****/
static Task_Params userTaskParams;
Task_Struct userTask;    /* not static so you can see in ROV */
static uint8_t userTaskStack[RFEASYLINKUSER_TASK_STACK_SIZE];

static void rfEasyLinkFuncFnx(UArg arg0, UArg arg1)
{
    DataBuff cache;
    while(1) {
        /***********************************************/
        /***********************************************/
        if(0 == Read_RingBuff((RingBuff*) &uart_buff, &cache))
        {
            UART_write(uart, &cache.data, cache.len);
            protocol_flash(&cache.data[0], cache.len);
        }
        /***********************************************/
        softTimer_Update();
        /***********************************************/
        /***********************************************/
        Task_sleep((500/Clock_tickPeriod));
        /***********************************************/
    }
}

void userFuncTask_init(void)
{
    Task_Params_init(&userTaskParams);
    userTaskParams.stackSize = RFEASYLINKUSER_TASK_STACK_SIZE;
    userTaskParams.priority = RFEASYLINKUSER_TASK_PRIORITY;
    userTaskParams.stack = &userTaskStack;
    userTaskParams.arg0 = (UInt)1000000;

    Task_construct(&userTask, rfEasyLinkFuncFnx, &userTaskParams, NULL);


}
